package com.zsj.qzt_punch.util;

import com.zsj.qzt_punch.pojo.Email;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
@Slf4j
public class SendEmail {

    public static void sendEmail(String body) throws Exception {
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String time = format.format(date);
        //发送邮件给我
        String userName = "1013361303@qq.com"; // 发件人QQ邮箱
        String password = "进去你的邮箱设置里去开启这个并且复制到这里";//激活POP3/SMTP服务的授权码
        String smtpHost = "smtp.qq.com"; // 邮件服务器
        String fromName = "zsj";//发件人名称
        String to = "邮箱地址"; // 收件人的邮箱账号，多个收件人以半角逗号分隔
        String cc = ""; //抄送，多个抄送以半角逗号分隔
        String subject = "打卡信息"; // 主题
//        String body = result.getMsg() + ",打卡时间为" + time;
        Email email = Email.entity(smtpHost, userName, password, to, cc, subject, body, null, fromName);
        email.send(); // 发送！
        log.info("邮件已发送~~~");
    }
}
